package com.expressage.controller;

import com.expressage.po.Site;
import com.expressage.service.SalaryService;
import com.expressage.service.SiteService;
import com.expressage.service.StaffService;
import com.expressage.service.StreetAddressService;
import com.expressage.vo.AdderVO;
import com.expressage.vo.StreetAddressVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class SiteController {
    @Autowired
    SiteService siteService;
    @Autowired
    StreetAddressService streetAddressService;
    Logger logger = Logger.getLogger(SiteController.class);

    @RequestMapping("jspafter/sitelist")
    public String findAll(Model model){
        logger.info("进入站点列表控制器");
        List<Site> list = siteService.findAll();
        model.addAttribute("sitelist",list);
        logger.info(list);
        return "jspafter/sitelist";
    }
    @RequestMapping("jspafter/sitelistone")
    public String findByid(int siteid,Model model){
        logger.info("进入站点对象控制器");
        Site site =  siteService.findByid(siteid);
        model.addAttribute(site);
        return "jspafter/sitelistone";
    }
    @RequestMapping("jspafter/sitefind")
    public String sitefindByStreet(Site site,Model model){

        int streetid=site.getStreetid();
        System.out.println("streetid"+streetid);;
        List<Site> list=siteService.findByStreetId(streetid);
        model.addAttribute("list",list);
       return "jspbefore/siteshow";
    }
    @RequestMapping("jspafter/toaddsite")
    public String addsite(){
        logger.info("去添加站点");
        return "jspafter/addsite";
    }

    @RequestMapping("jspafter/addsite")
    public String addsite(Site site){
        logger.info("进入站点添加控制器");
        boolean flag = siteService.add(site);
        logger.info(flag);
        return "redirect:sitelist.action";
    }


    @RequestMapping("jspafter/deletesite")
    public String deletesite(int[] array){
        logger.info("进入删除站点控制器");
        if(array.length>0){
            boolean falg = siteService.delete(array);
            logger.info(falg?true:false);
        }
        return "redirect:sitelist.action";
    }

}
